﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GongSolutions.Shell
{
    public partial class ExplorerToolBar : UserControl
    {
        public ToolStripButton backbutton;
        public ToolStripButton forwardbutton;
        private ToolStripSeparator toolStripSeparator1;
        public ToolStripButton upbutton;
        private ShellComboBox shellComboBox1;
        private ToolStrip toolStrip2;
        private ToolStripButton toolStripButton4;
        private ToolStripDropDownButton toolStripDropDownButton1;
        private ToolStrip toolStrip1;
        public ShellView ParentView { get; set; }
        public ToolStrip Strip { get { return this.toolStrip1; } }
        public ShellComboBox NavCombo { get { return this.shellComboBox1; } }
        public ToolStrip Strip2 { get { return this.toolStrip2; } }

        public ExplorerToolBar()
        {
            InitializeComponent();
            List<ShellViewStyle> Styles = Enum.GetValues(typeof(ShellViewStyle))
                                    .Cast<ShellViewStyle>()
                                    .ToList();
            foreach (ShellViewStyle Style in Styles)
            {
                ToolStripMenuItem m = new ToolStripMenuItem();
                m.Text = Style.ToString();
                m.Click += new EventHandler(thumbnailsToolStripMenuItem_Click);
                toolStripDropDownButton1.DropDownItems.Add(m);
            }
            this.shellComboBox1.ShellView = ParentView;
        }
        public void InitEvents()
        {
            this.shellComboBox1.ShellView = ParentView;
        }
        void ParentView_Navigated(object sender, EventArgs e)
        {
            this.backbutton.Enabled = ParentView.CanNavigateBack;
            this.forwardbutton.Enabled = ParentView.CanNavigateForward;
            this.upbutton.Enabled = ParentView.CanNavigateParent;
        }
        private void InitializeComponent()
        {
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.backbutton = new System.Windows.Forms.ToolStripButton();
            this.forwardbutton = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.upbutton = new System.Windows.Forms.ToolStripButton();
            this.toolStrip2 = new System.Windows.Forms.ToolStrip();
            this.toolStripButton4 = new System.Windows.Forms.ToolStripButton();
            this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
            this.shellComboBox1 = new GongSolutions.Shell.ShellComboBox();
            this.toolStrip1.SuspendLayout();
            this.toolStrip2.SuspendLayout();
            this.SuspendLayout();
            // 
            // toolStrip1
            // 
            this.toolStrip1.AutoSize = false;
            this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
            this.toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.backbutton,
            this.forwardbutton,
            this.toolStripSeparator1,
            this.upbutton});
            this.toolStrip1.Location = new System.Drawing.Point(0, 1);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            this.toolStrip1.Size = new System.Drawing.Size(115, 25);
            this.toolStrip1.TabIndex = 0;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // backbutton
            // 
            this.backbutton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.backbutton.Image = global::SS.Ynote.Packages.Properties.Resources.Back;
            this.backbutton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.backbutton.Name = "backbutton";
            this.backbutton.Size = new System.Drawing.Size(24, 22);
            this.backbutton.Text = "Back";
            this.backbutton.Click += new System.EventHandler(this.toolStripButton1_Click);
            // 
            // forwardbutton
            // 
            this.forwardbutton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.forwardbutton.Image = global::SS.Ynote.Packages.Properties.Resources.Forward;
            this.forwardbutton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.forwardbutton.Name = "forwardbutton";
            this.forwardbutton.Size = new System.Drawing.Size(24, 22);
            this.forwardbutton.Text = "Forward";
            this.forwardbutton.Click += new System.EventHandler(this.toolStripButton2_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
            // 
            // upbutton
            // 
            this.upbutton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.upbutton.Image = global::SS.Ynote.Packages.Properties.Resources.Up;
            this.upbutton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.upbutton.Name = "upbutton";
            this.upbutton.Size = new System.Drawing.Size(24, 22);
            this.upbutton.Text = "Up";
            this.upbutton.Click += new System.EventHandler(this.toolStripButton3_Click);
            // 
            // toolStrip2
            // 
            this.toolStrip2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.toolStrip2.AutoSize = false;
            this.toolStrip2.Dock = System.Windows.Forms.DockStyle.None;
            this.toolStrip2.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolStrip2.ImageScalingSize = new System.Drawing.Size(20, 20);
            this.toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripButton4,
            this.toolStripDropDownButton1});
            this.toolStrip2.Location = new System.Drawing.Point(504, 1);
            this.toolStrip2.Name = "toolStrip2";
            this.toolStrip2.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
            this.toolStrip2.Size = new System.Drawing.Size(76, 25);
            this.toolStrip2.TabIndex = 2;
            this.toolStrip2.Text = "toolStrip2";
            // 
            // toolStripButton4
            // 
            this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton4.Image = global::SS.Ynote.Packages.Properties.Resources.NewFolder;
            this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton4.Name = "toolStripButton4";
            this.toolStripButton4.Size = new System.Drawing.Size(24, 22);
            this.toolStripButton4.Text = "New Folder";
            this.toolStripButton4.Click += new System.EventHandler(this.toolStripButton4_Click);
            // 
            // toolStripDropDownButton1
            // 
            this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripDropDownButton1.Image = global::SS.Ynote.Packages.Properties.Resources.Views;
            this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
            this.toolStripDropDownButton1.Size = new System.Drawing.Size(33, 22);
            this.toolStripDropDownButton1.Text = "View";
            // 
            // shellComboBox1
            // 
            this.shellComboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.shellComboBox1.Editable = true;
            this.shellComboBox1.Location = new System.Drawing.Point(88, 3);
            this.shellComboBox1.Name = "shellComboBox1";
            this.shellComboBox1.Size = new System.Drawing.Size(413, 20);
            this.shellComboBox1.TabIndex = 1;
            this.shellComboBox1.Text = "shellComboBox1";
            // 
            // ExplorerToolBar
            // 
            this.Controls.Add(this.toolStrip2);
            this.Controls.Add(this.shellComboBox1);
            this.Controls.Add(this.toolStrip1);
            this.Name = "ExplorerToolBar";
            this.Size = new System.Drawing.Size(570, 29);
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.toolStrip2.ResumeLayout(false);
            this.toolStrip2.PerformLayout();
            this.ResumeLayout(false);

        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            this.ParentView.NavigateBack();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.ParentView.NavigateForward();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.ParentView.NavigateParent();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            this.ParentView.CreateNewFolder();
        }

        private void thumbnailsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            ParentView.View = EnumHelper.FromString<ShellViewStyle>(item.Text);
        }
    }
    public static class EnumHelper
    {
        public static T FromString<T>(string value)
        {
            return (T)Enum.Parse(typeof(T), value);
        }
    }
}
